package com.example.sale.Service.imply;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.sale.Mapper.UserDetailMapper;
import com.example.sale.Service.IUserDetailService;
import com.example.sale.True.Birthday;
import com.example.sale.True.UserDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class UserDetailService extends ServiceImpl<UserDetailMapper, UserDetail> implements IUserDetailService {
    @Autowired
    private UserDetailMapper userDetailMapper;
    public IPage<UserDetail> searchUsers(Page<UserDetail> page,Map<String, Object>params) {
        QueryWrapper<UserDetail> wrapper = new QueryWrapper<>();

        // 根据传入的params参数，构造查询条件
        if (params.containsKey("name")) {
            String name = (String) params.get("name");
            wrapper.eq("name", name);
        }
        if (params.containsKey("age")) {
            Integer age = (Integer) params.get("age");
            wrapper.eq("age", age);
        }
        if (params.containsKey("address")) {
            String address = (String) params.get("address");
            wrapper.eq("address", address);
        }
        return baseMapper.selectPage(page, wrapper);
    }
    @Override
    public boolean isUsernameExists(Integer id) {
        UserDetail CheckId = userDetailMapper.findBykeyid(id);
        return CheckId!=null;
    }

    @Override
    public UserDetail getByTokenId(Integer id) {
        UserDetail CheckId = userDetailMapper.findBykeyid(id);
        return CheckId;
    }

    @Override
    public String getByPhotoId(Integer id) {
        String Photo = userDetailMapper.findPhoto(id);
        return Photo;
    }

    @Override
    public String getByNameId(Integer id) {
        String Name = userDetailMapper.findName(id);
        return Name;
    }

    @Override
    public boolean isUserDetailExists(Integer id) {
        UserDetail CheckId = userDetailMapper.findBykeyid(id);
        return CheckId!=null;
    }

    @Override
    public String GetAgeNumberLess(Integer age) {
        String MoreNumber = userDetailMapper.findAgeMore(age);
        return MoreNumber;
    }

    @Override
    public String GetAgeNumberMore(Integer age) {
        String LessNumber = userDetailMapper.findAgeLess(age);
        return  LessNumber;
    }

    @Override
    public String findGenderNumber(String gender) {
        String genderNumber = userDetailMapper.findGenderNumber(gender);
        return genderNumber;
    }

    @Override
    public List<Birthday> findBirthdayNumber(String month) {
        List<Birthday> BirthdayNumber = userDetailMapper.getBirthDayNumber(month);
        return BirthdayNumber;
    }

    @Override
    public String getQQNumber(String username) {
        String qq = userDetailMapper.getQQNumber(username);
        return qq;
    }

    @Override
    public String getPassword(String username) {
        String password = userDetailMapper.getPassword(username);
        return  password;
    }
    @CacheEvict(value = "pageData", allEntries = true)
    public void clearCache() {
        // 清除所有与 "pageData" 缓存相关的数据
    }
}
